import 'package:chat_shop/common/const/cosnt.dart';
import 'package:flutter/material.dart';
import 'package:pin_input_text_field/pin_input_text_field.dart';

class InputPwdView extends StatefulWidget {
  final Function(String sender)? onChanged;
  final bool isobscure;
  final Color borderColor;
  final Color backColor;
  const InputPwdView(
      {Key? key,
      this.onChanged,
      this.backColor = Colors.white,
      this.isobscure = false,
      this.borderColor = AppColor.mainColor})
      : super(key: key);
  @override
  _InputPwdViewState createState() => _InputPwdViewState();
}

class _InputPwdViewState extends State<InputPwdView> {
  final _pinEditingController = TextEditingController();
  @override
  void dispose() {
    _pinEditingController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 48,
      alignment: Alignment.center,
      // padding: const EdgeInsets.symmetric(horizontal: 27),
      child: PinInputTextField(
        pinLength: 6,
        decoration: BoxLooseDecoration(
          textStyle: AppFont.textStyle(15, color: AppColor.font333),
          strokeColorBuilder: PinListenColorBuilder(widget.borderColor, widget.borderColor),
          strokeWidth: 1.0,
          bgColorBuilder: PinListenColorBuilder(widget.backColor, widget.backColor),
          gapSpace: 6,
          obscureStyle: ObscureStyle(
            isTextObscure: widget.isobscure,
            obscureText: '●',
          ),
        ),
        controller: _pinEditingController,
        textInputAction: TextInputAction.done,
        enabled: true,
        autoFocus: true,
        keyboardType: TextInputType.number,
        textCapitalization: TextCapitalization.characters,
        onSubmit: (pin) {
          debugPrint('submit pin:$pin');
        },
        onChanged: (pin) {
          if (widget.onChanged != null) widget.onChanged!(pin);
        },
        enableInteractiveSelection: true,
      ),
    );
  }
}
